package com.yeping.controller;

import com.yeping.domain.ResponseResult;
import com.yeping.domain.dto.AddArticleDto;
import com.yeping.domain.entity.Article;
import com.yeping.service.ArticalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/article")
public class ArticleController {
    @Autowired
    private ArticalService articalService;

//    @GetMapping("/list")
//    public List<Article> list(){
//        return articalService.list();
//    }

    @GetMapping("/hotArticleList")
    public ResponseResult hotArticleList(){
        ResponseResult result = articalService.hotArticleList();
        return result;
    }

    @GetMapping("/articleList")
    public ResponseResult articleList(Integer pageNum,Integer pageSize,Long categoryId,String title,String isForum){
        return articalService.articleList(pageNum,pageSize,categoryId,title,isForum);
    }

    @GetMapping("/articleAll")
    public ResponseResult articleAll(String isForum,Long categoryId,String summary){
        return articalService.articleAll(isForum,categoryId,summary);
    }

    @PutMapping("/updateViewCount/{id}")
    public ResponseResult updateViewCount(@PathVariable("id") Long id){
        return articalService.updateViewCount(id);
    }

    @GetMapping("/{id}")
    public ResponseResult getArticalDetail(@PathVariable Long id){
        return articalService.getArticalDetail(id);
    }

    @PostMapping
    public ResponseResult add(@RequestBody AddArticleDto article){

        return articalService.add(article);

    }

    @GetMapping
    public ResponseResult seacherArtical(String keyword){
        return articalService.seacherArtical(keyword);
    }

    @PutMapping
    public ResponseResult updateLike(@RequestBody Article article){
        return articalService.updateLike(article);
    }

    @GetMapping("/getTags")
    public ResponseResult getTags(Long articleId){
        return articalService.getTags(articleId);
    }
}
